<?php get_header(); ?>
<!-- Content -->
<div id="content" class="wrap">
  <!-- main -->
  <div class="main">
    <!-- crumbs -->
    <div class="wz bom"><?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?></div>
    <!-- finxed -->
	<div class="fixed string left bom">
	  <div class="sort_by">
		<h4 class="h4">排序</h4>
		<ul>
		  <li><a <?php if ( isset($_GET['order']) && ($_GET['order']=='rand') ) echo 'class="current"'; ?> href="<?php echo curPageURL() . '?' . http_build_query(array_merge($_GET, array('order' => 'rand'))); ?>">随机阅读</a>
          </li>
	      <li><a <?php if ( isset($_GET['order']) && ($_GET['order']=='commented') ) echo 'class="current"'; ?> href="<?php echo curPageURL() . '?' . http_build_query(array_merge($_GET, array('order' => 'commented'))); ?>">评论最多</a>
          </li>
		  <li><a <?php if ( isset($_GET['order']) && ($_GET['order']=='alpha') ) echo 'class="current"'; ?> href="<?php echo curPageURL() . '?' . http_build_query(array_merge($_GET, array('order' => 'alpha'))); ?>">标题排序</a>
          </li>
		</ul>
	  </div>
	  <h4 class="h4">浏览<?php
			// If this is a category archive
			if (is_category()) {
				printf('分类</h4>
			<h5>'.single_cat_title('', false).'</h5>' );
				if (category_description()) echo '<p>'.category_description().'</p>';
			// If this is a tag archive
			} elseif (is_tag()) {
				printf('标签</h4>
			<h5>'.single_tag_title('', false).'</h5>' );
				if (tag_description()) echo '<p>'.tag_description().'</p>';
			// If this is a daily archive
			} elseif (is_day()) {
				printf('日期存档</h4>
			<h5>'.get_the_time('Y年n月j日').'</h5>' );
			// If this is a monthly archive
			} elseif (is_month()) {
				printf('月份存档</h4>
				<h5>'.get_the_time('Y年n月').'</h5>' );
			// If this is a yearly archive
			} elseif (is_year()) {
				printf('年份存档</h4>
				<h5>'.get_the_time('Y年').'</h5>' );
				// If this is an author archive
			} elseif (is_author()) {
					echo '作者存档';
			// If this is a paged archive
			} elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {
				echo '博客存档';
			}
			?>
	</div>
    <!-- Blog Post -->
<?php
global $wp_query;
if ( isset($_GET['order']) && ($_GET['order']=='rand') ) {
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	$args=array(
		'orderby' => 'rand',
		'paged' => $paged,
	);
	$arms = array_merge(
		$args,
		$wp_query->query
	);
	query_posts($arms);
}
else if ( isset($_GET['order']) && ($_GET['order']=='commented') ){
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	$args=array(
		'orderby' => 'comment_count',
		'order' => 'DESC',
		'paged' => $paged,
	);
    $arms = array_merge(
		$args,
		$wp_query->query
	);
    query_posts($arms);
}
else if ( isset($_GET['order']) && ($_GET['order']=='alpha') ){
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	$args=array(
		'orderby' => 'title',
		'order' => 'ASC',
		'paged' => $paged,
	);
    $arms = array_merge(
		$args,
		$wp_query->query
	);
    query_posts($arms);
} if (have_posts()) : while (have_posts()) : the_post(); 
?>
    <div class="grid_2 bom right">
    <div class="img1"><img onload="AutoImage(170,0,this)" src="<?php echo catch_that_image() ?>"/></div>
	<div class="post">
			<!-- Post Title -->
			<h4 class="title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h4>
			<!-- Post Data -->
        <div class="sub">
          <i class="user"></i><span> <?php the_author(); ?></span>
          <i class="date"></i><span><?php the_time('Y.n.j') ?></span>
          <i class="chat"></i><span><?php comments_popup_link('0', '1', '%', '', '评论已关闭'); ?></span>
          <i class="tag"></i><span><?php the_tags((' '), '、'); ?></span>
        </div>
			<!-- Post Content -->
			<?php the_excerpt(); ?>
			<!-- Read More Button -->
	  <div class="read right"><a href="<?php the_permalink(); ?>">阅读全文</a></div>
	</div>
    </div>
		<?php endwhile; ?>	
		<?php else : ?>
		<h1 class="title"><a href="#" rel="bookmark">未找到</a></h1>
		<p>没有找到任何文章！</p>
	<?php endif;wp_reset_postdata(); ?>    
    <!-- page style -->
    <div class="paging">
    <?php par_pagenavi(9); ?> 
    </div>  
	</div>
<?php get_sidebar(); ?>
<div class="links"></div>
<?php get_footer(); ?>
